package com.india.project.push.controller;

import com.github.pagehelper.PageInfo;
import com.india.common.constant.HttpStatus;
import com.india.framework.web.page.TableDataInfo;
import com.india.project.push.domain.SoBarcodeDetail;
import com.india.project.push.domain.SoHvBarcodeVo;
import com.india.project.push.service.ISoBarcodeDetail;
import com.india.project.push.service.ISoHvBarCodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.india.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/push/details")
public class SoBarcodeDetailController {
    @Autowired
    private ISoBarcodeDetail soBarcodeDetail;
    @Autowired
    private ISoHvBarCodeVo soHvBarCodeVo;
    @GetMapping("/list")
    public TableDataInfo list(){
        startPage();
        List<SoBarcodeDetail> soBarcodeDetails = soBarcodeDetail.selectList();
        return getDataTable(soBarcodeDetails);
    }

    @GetMapping("/all")
    public TableDataInfo all(){
        startPage();
        List<SoHvBarcodeVo> soHvBarcodeVos = soHvBarCodeVo.searchAll();
        return getDataTable(soHvBarcodeVos);
    }

    /**
     * 响应请求分页数据
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected TableDataInfo getDataTable(List<?> list)
    {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }
}
